package pe.gob.foncodes.ssa.bs.common.util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRAbstractExporter;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;


public class PdfExporterDecorator extends JRAbstractExporter {

    private JRExporter exporter = null;
    private SerializedList jp = null;
    private HttpServletResponse response = null;

    public PdfExporterDecorator(JRExporter exporter, SerializedList jasperPrintList, HttpServletResponse response) {
        this.exporter = exporter;
        this.jp = jasperPrintList;
        this.response = response;
    }

    @Override
    public void exportReport() throws JRException {
        JRExporter temp = null;
        try {
            temp = JRExporterStrategyFactory.getInstance().get("pdf").export(jp, response);
        } catch (Exception e) {
            throw new JRException(e.getMessage(), e);
        }
        temp.exportReport();
        FacesContext.getCurrentInstance().responseComplete();
        exporter.exportReport();
    }

 
    @Override
    protected String getExporterKey() throws JRException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}